package com.example.android_api;

import com.example.android_api.adapter.ImageAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

public class MainActivity extends Activity {

	GridView gridView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		gridView = (GridView) findViewById(R.id.gridView1);
		gridView.setAdapter(new ImageAdapter(this));
		
		gridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View v, int position,
					long id) {
				// TODO Auto-generated method stub
//				Toast.makeText(MainActivity.this, ""+position, Toast.LENGTH_SHORT).show();
				//为图标指定activity
				Intent intent = null;
				switch (position) {
				case 0:
					intent = new Intent(MainActivity.this, SaveDataActivity.class);
					startActivity(intent);
					break;
				case 1:
					
					break;
				default:
					break;
				}
			}
		});
		/*.setOnItemClickListener(new OnItemClickListener() {
		        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		            Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
		        }
		    });*/
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
